package org.come.init;

import java.awt.Font;
import java.awt.Image;
import java.awt.Toolkit;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

import org.come.until.Util;


@SuppressWarnings("serial")
public class GetUpdatesFram extends JFrame implements Runnable {
	// 定义加载窗口大小
	public static final int LOAD_WIDTH = 377;
	public static final int LOAD_HEIGHT = 123;
	// 获取屏幕窗口大小
	public static final int WIDTH = Toolkit.getDefaultToolkit().getScreenSize().width;
	public static final int HEIGHT = Toolkit.getDefaultToolkit().getScreenSize().height;
	
	public static CheckUpdateFrame checkUpdate;

	// 定义标签组件
	public JLabel label, info;
	public String [] infoText = new String [ ]{"获取服务器列表", "获取服务器列表.", "获取服务器列表..", "获取服务器列表...","获取服务器列表....","     检查更新", "     检查更新.", "     检查更新..", "     检查更新...", "     检查更新...."};
	public GetUpdatesFram() {
		// 创建标签,并在标签上放置一张图片
		label = new JLabel(new ImageIcon("resource/NewUi/loginGetNew.png"));
		label.setBounds(0, 0, LOAD_WIDTH, LOAD_HEIGHT);
		info = new JLabel("获取服务器列表");
		info.setFont(new Font("宋体", Font.PLAIN, 11));
		info.setBounds(140, 45, 100, 20);
		//表示先获取一个Toolkit对象方便添加图标
		Toolkit tool = this.getToolkit();
		//表示通过Toolkit对象初始化一个Image对象
		Image myimage = tool.getImage("skin/9000026/new_img/icon/logo.png");
		this.setIconImage(myimage);
		this.add(info);
		this.setUndecorated(true);//去掉所有东东,只显示窗口
		this.setResizable(false);//禁止用户修改窗体大小
		// 添加组件
		this.add(label);
		// 设置布局为空
		this.setLayout(null);
		// 设置窗口初始位置
		this.setLocation((WIDTH - LOAD_WIDTH) / 2, (HEIGHT - LOAD_HEIGHT) / 2);
		// 设置窗口大小
		this.setSize(LOAD_WIDTH, LOAD_HEIGHT);
		// this.setSize(label.getWidth(),label.getHeight());
		// 设置窗口显示
		this.setVisible(true);
	}
	public static void main(String[] args) {
		GetUpdatesFram gl = new GetUpdatesFram();
		new Thread(gl).start();
	}
	public void run() {
		//System.out.println(i);
		int random = Util.random.nextInt(6);
		System.out.println(random);
		for (int i = 0; i < infoText.length; i += 1) {
			try {
				Thread.sleep((random + 1)* 50);
				info.setText(infoText[i]);
			}
			catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		// 此处调用游戏GameLoading页面
//		JOptionPane.showMessageDialog(this, "加载完成");
		this.dispose();
        checkUpdate = new CheckUpdateFrame();
        Thread thread = new Thread(checkUpdate);
        thread.start();
	}
}
